% Splitting data into streams and computing number of bits for arithmetic
% coding without auxilary information
function [streams] = split(data, context, T)
	n = length(data); % length of data stream
	Mi = min(context); % minimum context value
	Ma = max(context); %maximum context value
	i = Mi;%context value
	total = 0; %length of the processed part of data
	streams = cell(0);
	idx = 1;
	
    while ((i <= Ma) & (n - total) > round(n / T))
        	counter = 0;  
       		D = zeros(1, round(2 * n / T));
        	while (counter < round(n / T))
        		I = find(context == i);
        		l = length(I);
        		D((counter + 1):(counter + l)) = data(I);%substream, corresponding to one context value (joint neighboring context values)  
                counter = counter + l;
        		i = i + 1;
        	end;
    		streams{idx} = D(1:(counter));
            idx = idx + 1;
    		total = total + counter;
	end;

	counter = 0;
	D = zeros(1, round(2 * n / T));
	if (n ~= total) 
		for j = i:Ma
            I = find(context == j);
        	l = length(I);
        	D((counter + 1):(counter + l)) = data(I);
        	counter = counter + l;
    	end;
    	streams{idx} = D(1:counter);
    end;
end
